package com.budwk.app.util;

import org.apache.commons.lang3.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author ZY.Wang
 * @since 2023/5/19
 */
public class AudioToTextUtils {

    // 该方法的主要作用是将通话记录中的中括号时间内的内容替换掉
    public static String replaceMsgContent(String msg) {
        if (StringUtils.isBlank(msg)) return null;
        String reg = "\\[.+\\]";
        Pattern compile = Pattern.compile(reg);
        Matcher matcher = compile.matcher(msg);

        int talkIndex = 1;
        while (matcher.find()) {
            String group = matcher.group();
            String s = "[对话" + talkIndex + "]:";
            msg = msg.replace(group, s);
            talkIndex++;
        }

        return msg;
    }

    public static String replaceMsgContentNotPrefix(String msg) {
        if (StringUtils.isBlank(msg)) return null;
        String reg = "\\[.+\\]";
        Pattern compile = Pattern.compile(reg);
        Matcher matcher = compile.matcher(msg);

        while (matcher.find()) {
            String group = matcher.group();
            String s = "";
            msg = msg.replace(group, s);
        }

        return msg;
    }
}
